package com.library.workbench.service.impl;

import com.library.workbench.mapper.BookMapper;
import com.library.workbench.pojo.Book;
import com.library.workbench.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("bookService")
public class BookServiceImpl implements BookService {
    @Autowired
    private BookMapper bookMapper;

    @Override
    public List<Book> queryBookByConditionForPage(Map<String, Object> map) {
        return bookMapper.queryBooksByNameOrAuthorOrPublisherForPage(map);
    }

    @Override
    public List<Book> queryAllBooks() {
        return bookMapper.selectAll();
    }

    @Override
    public int queryRowsSum(Map<String, Object> map) {
        return bookMapper.queryRowsCount(map);
    }

    @Override
    public int saveCreateBook(Book book) {
        return bookMapper.saveCreateBook(book);
    }

    @Override
    public int deleteBookByBookId(String bookId) {
        Book book = bookMapper.selectBookByBookId(bookId);
        // 书籍不在库不允许删除
        if (book==null||"0".equals(book.getExist())){
            return 0;
        }
        return bookMapper.deleteBookByBookId(bookId);
    }

    @Override
    public Book queryBookByBookId(String bookId) {
        return bookMapper.selectBookByBookId(bookId);
    }

    @Override
    public int updateBookByBookId(Book book) {
        return bookMapper.updateBookByBookId(book);
    }
}
